package com.dci.controller;

import com.dci.context.Config;
import com.dci.dao.pms.SysAclModuleMapper;
import com.dci.model.SysAclModule;
import com.dci.result.ExceptionResultInfo;
import com.dci.result.ResultInfo;
import com.dci.result.ResultUtil;
import com.dci.util.ApplicationContextHelper;
import com.dci.util.JsonMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * All rights Reserved, Designed By 姑苏区政府大数据中心
 *
 * @version V1.0
 * @Title: null.java
 * @Package com.dci.controller
 * @Description: 测试控制类
 * @author: 张星亮
 * @date: 2019/2/25
 * @Copyright: 2019 姑苏区政府大数据中心. All rights reserved.
 * 注意：本内容仅限于姑苏区政府大数据中心内部传阅，禁止外泄以及用于其他的商业目
 */
@RestController
@Slf4j
public class TestController {

    @Resource
    private HttpMessageConverter<ExceptionResultInfo> jsonMessageConverter;

    /**
     * 测试全局异常处理器
     *
     * @return
     */
    @GetMapping("/exceptionTest")
    @ResponseBody
    public ResultInfo exception() {
        int a = 1;
        if (a == 1) {
            return ResultUtil.createSuccess(Config.MESSAGE, 201, null);
        }
        return new ResultInfo();
    }

    /**
     * 查看后台日志
     *
     * @return
     */
    @GetMapping("/contextTest")
    @ResponseBody
    public String context() {
        SysAclModuleMapper sysAclModuleMapper = ApplicationContextHelper.getBean(SysAclModuleMapper.class);
        SysAclModule module = sysAclModuleMapper.selectByPrimaryKey(1);
        log.info(JsonMapper.obj2String(module));
        return "查看后台日志";
    }

    /**
     * 异常查看
     *
     * @return
     */
    @GetMapping("/exceptionTest2")
    @ResponseBody
    public ResultInfo exceptionTest() {
        int a = 0;
        int b = 1 / a;
        if (b == 1) {
            return ResultUtil.createSuccess(Config.MESSAGE, 201, null);
        }
        return new ResultInfo();
    }


}
